package com.cloud.pole.shop.biz.goods;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.goods.ShopGoodsSpecMapper;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsSpec;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopGoodsSpecBiz extends BaseBiz<ShopGoodsSpecMapper, ShopGoodsSpec> {
	
	@Autowired
	ShopGoodsSpecMapper shopGoodsSpecMapper;
	
	@Cache(key="shopGoodsSpec{1}")
    public ShopGoodsSpec selectById(Integer spceId) {
		 return super.selectById(spceId);
    }
	
	@Cache(key="shopGoodsSpecList{1}")
    public List<ShopGoodsSpec> selectListByGoodsId(Integer goodsId) {
		 Example example = new Example(ShopGoodsSpec.class);
		 Criteria criteria = example.createCriteria();
         //example.setOrderByClause("order_level");
		 criteria.andEqualTo("goodsId", goodsId);
		 return selectByExample(example);
    }
	
	@Override
	@CacheClear(keys= {"shopGoodsSpec{1.spceId}", "shopGoodsSpecList{1.goodsId}"})
	public void updateSelectiveById(ShopGoodsSpec shopGoodsSpec) {
		super.updateSelectiveById(shopGoodsSpec);
	}
	
	@Override
	@CacheClear(keys= {"shopGoodsSpec", "shopGoodsSpecList"})
	public void delete(ShopGoodsSpec shopGoodsSpec) {
		super.delete(shopGoodsSpec);
	}

	@CacheClear(keys= {"shopGoodsSpec", "shopGoodsSpecList"})
	public void deleteByGoodsId(Integer goodsId) {
		shopGoodsSpecMapper.deleteByGoodsId(goodsId);
	}
	
	@CacheClear(keys= {"shopGoodsSpec", "shopGoodsSpecList"})
	public void add(ShopGoodsSpec shopGoodsSpec) {
		shopGoodsSpecMapper.addGoodsSpec(shopGoodsSpec);
	}
}
